package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.dto.SysDictDataDTO;
import com.rabbit.eap.system.param.SysDictDataPageParam;
import com.rabbit.eap.system.service.ISysDictDataService;
import com.rabbit.eap.system.vo.SysDictDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysDictDataController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 字典数据表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysDictData")
@Module("system")
@Api(value = "字典数据表API", tags = {"字典数据表"})
public class SysDictDataController extends BaseController {

    @Autowired
    private ISysDictDataService sysDictDataService;


    /**
    * @Description: 添加字典数据表
    * @methodName: saveSysDictData
    * @param sysDictDataDTO:sysDictDataDTO数据传输对象
    * @return: ApiResult.result(flag)
    * @date: 2020/06/06 23:05:26
    * @author: rabbit
    */
    @PostMapping("/saveSysDictData")
    @RequiresPermissions("sys:dict:add")
    @OperationLog(name = "添加字典数据表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加字典数据表", response = ApiResult.class)
    public ApiResult saveSysDictData(@Validated(AddGroup.class) @RequestBody SysDictDataDTO sysDictDataDTO) throws Exception {
        ApiResult apiResult = sysDictDataService.saveSysDictData(sysDictDataDTO);
        return apiResult;
    }
    /**
     * @Description: 修改字典数据表
     * @methodName: modifySysDictData
     * @param  sysDictDataDTO:sysDictDataDTO数据传输对象
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysDictData")
    @RequiresPermissions("sys:dict:edit")
    @OperationLog(name = "修改字典数据表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改字典数据表", response = ApiResult.class)
    public ApiResult modifySysDictData(@Validated(UpdateGroup.class) @RequestBody SysDictDataDTO sysDictDataDTO) throws Exception {
        ApiResult  apiResult = sysDictDataService.modifySysDictData(sysDictDataDTO);
        return apiResult;
    }
    /**
     * @Description: 删除字典数据表
     * @methodName: removeSysDictData
     * @param ids:id集合
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysDictData")
    @RequiresPermissions("sys:dict:remove")
    @OperationLog(name = "删除字典数据表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除字典数据表", response = ApiResult.class)
    public ApiResult  removeSysDictData(@RequestParam("ids") Long[] ids) throws Exception {
        ApiResult  apiResult = sysDictDataService.removeSysDictData(ids);
        return apiResult;
    }

    /**
     * @Description: 根据Id获取字典数据表详情
     * @methodName: getSysDictDataInfo
     * @param id: id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysDictDataInfo")
    @RequiresPermissions("sys:dict:query")
    @OperationLog(name = "字典数据表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "字典数据表详情", response = SysDictDataVO.class)
    public ApiResult getSysDictDataInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysDictDataService.getSysDictDataById(id);
        return apiResult;
    }

    /**
     * @Description: 字典数据表分页列表
     * @methodName: getSysDictDataPageList
     * @param sysDictDataPageParam
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysDictDataPageList")
    @RequiresPermissions("sys:dict:list")
    @OperationLog(name = "字典数据表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "字典数据表分页列表", response = SysDictDataVO.class)
    public ApiResult getSysDictDataPageList(SysDictDataPageParam sysDictDataPageParam) throws Exception {
        ApiResult  apiResult = sysDictDataService.getSysDictDataPageList(sysDictDataPageParam);
        return apiResult;
    }
    /**
     * @Description: 根据字典类型查询字典数据信息
     * @methodName: getSysDictDataByDictType
     * @param dictTypeId: 字典类型Id
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/17 19:14
     * @author: rabbit
     *
     */
    public ApiResult getSysDictDataByDictType(@RequestParam("dictTypeId")  Long  dictTypeId){
        ApiResult apiResult  = sysDictDataService.getSysDictDataByDictType(dictTypeId);
        return apiResult;
    }
}

